home *** CD-ROM | disk | FTP | other *** search
- Path: uuneo.neosoft.com!usenet
- From: Wmatthew@lan-aces.com (W. Matthews)
- Newsgroups: comp.lang.c++
- Subject: Re: template with unknown classes!
- Date: 14 Mar 1996 16:19:04 GMT
- Organization: LAN-ACES, Inc.
- Message-ID: <4i9gto$dtu@uuneo.neosoft.com>
- References: <3146F7D0.791D@nada.kth.se>
- NNTP-Posting-Host: 198.65.178.8
- X-Newsreader: WinVN 0.92.5
-
- In article <3146F7D0.791D@nada.kth.se>, Andreas SwΣrdh <da1-asw@nada.kth.se> says:
- >
- >My real problem is that I havn't found any good referens about
- >advance templates.
- >
- >So my question is: If you got an exemple like the one below
- >is there an solution to find?
- >
- >class listhandler
- >{
- > private:
- > node *head; // my baseclass pointer. could be a Void* too, just
- > public: // to make it even more complicated.
- > listhandler(){head = null;};
- > void new_object(); // here is the functions definition.
- > ...
- > ...
- >}
- >// I Would like to create an listhandler that works on everything. That
- >can
- >// take an unknown class (of course it must be a defined class) and
- >create it
- >// with NEW. I thought it would be easy to do with templates but haven't
- >had
- >// any success yet. The problem is that I don't want the hole class to
- >be a
- >// template, just THIS funktion. Is there a solution with templetes or
- >do
- >// you have to use friend in some sort of way? Maybe use of
- >dummy-class-pointer
- >// just to get the right class type?! Would be most greatful for fast
- >replies.
- >
- >// The possible function?!
- >
- >template<class object>void new_object() // or something like that!
- >{
- > if(!head)
- > head = new object; // where object doesn't have to be known.
- > ... // And the constuctor of object initializes it!
- > ...
- >}
- >
- >// It shall be intresting to see what kind of solutions you can dig out
- >// of your closet!
- >//
- >// If you wanna mail me personaly: MAILTO:da1_asw@nada.kth.se
- >//
- >// Bye for know!!
- how about a friend function? Another post on comp.lang.c++ was asking
- about templating a single function....
- ______________________________________________
- |Wyatt Matthews: Tech Support Department |
- |WMATTHEW@LAN-ACES.COM -Internet- |
- |WMATTHEW.MHS@LAN-ACES -MHS- |
- |LAN-ACES Tech Support (713)890-9786 |
- |LAN-ACES BBS (713)890-9790 |
- |LAN-ACES Fax (713)890-9731 |
- |LAN-ACES Sales (713)890-9787 |
- ______________________________________________
-